/* 通用提交审核界面 */
<template>
  <vol-box
    :lazy="true"
    v-model="model"
    title="提交/回退"
    :height="300"
    :width="1000"
    :draggable="true"
    :padding="5"
  >
    <div>
      <el_step ref="el_step"></el_step>
      
      <VolForm ref="myform" :formFields="formFields" :formRules="formRules">
        <div style="text-align: center; margin-top: 10px"></div>
      </VolForm>
      <font color="red">
      说明：<br>回退：退到前一步骤或者退到指定步骤<br>不同意：退给起草人步骤</font>
      <jroadeparttree ref="jroadeparttree"></jroadeparttree>
    </div>
    <template #footer>
      <div>
        <el-button type="primary" size="mini" @click="tijiao()">提交</el-button>
        <!-- <el-button type="primary" size="mini" @click="model = false"
          >关闭</el-button
        > -->
        <el-button type="primary" size="mini" @click="guanbi()"
          >关闭</el-button
        >
      </div></template
    >
  </vol-box>
</template>
<script>
import jroadeparttree from "@/extension/system/float/jroa_depart_tree.vue"
import VolBox from "@/components/basic/VolBox.vue";
import el_step from "@/extension/system/float/el_step.vue";
import VolHeader from "@/components/basic/VolHeader.vue";
import VolForm from "@/components/basic/VolForm.vue";
//这里使用的vue2语法，也可以写成vue3语法
export default {
  components: { "vol-box": VolBox, el_step, VolHeader, VolForm, jroadeparttree},
  methods: {},
  data() {
    return {
      
      model: false,
      loadKey: true,
      index: 1,
      required: false,
      formFields: {
        reyijian: "同意",
        //Variety: "",
        remark: "", // this.$store.getters.data().curr_reimfloat_remark,
      },
      formRules: [
        [
          {
            title: "提交意见",
            required: true,
            field: "reyijian",
            type: "string",
            data: [
              { key: "同意", value: "同意" },
              { key: "回退", value: "回退" },
              { key: "不同意", value: "不同意" },
            ],
            type: "select",
            colSize: 3,
          },
          {
            title: "退到指定步骤",
            required: false,
            field: "to_stepid",
            type: "string",
            data: [],
            type: "select", 
            colSize: 3,
          },
        ],
        [
          {
            title: "意见详情",
            required: false,
            field: "remark",
            type: "textarea",
            height: 210,
          },
        ],
      ],
    };
  },
  methods: {
    openwin(modelname) {
      this.model = true;
      //
      this.formFields.remark="";
      this.$nextTick(() => {
        let ss_string=this.$store.getters.data().ss_string.split(',');
        
        this.$refs.jroadeparttree.get_dep_fortree(-1);
         this.http.post("/api/fk_reimfloat/get_curr_reimfloat?reim_id="+ss_string[0], {}, true).then((s) => {
              let steplist=s.map(s=>{
                return {
                    key:s.stepid,
                    value:s.stepname,
                }});
                this.formRules.forEach(e=>{//循环给volform字段赋值
                  e.forEach(ee=>{
                    if (ee.field=="to_stepid"){
                        ee.data=steplist;
                    }
                  })
                })
            
         });
         
         
      });
    },
    tijiao() { 
      if(this.formFields.reyijian == '回退'){
        if (this.formFields.to_stepid == undefined) {
           this.$message.error("如果提交意见为回退，则退到指定步骤必填");
           return;
        }
      }
      let postdata = this.formFields;
      var pdata = encodeURIComponent(JSON.stringify(postdata)); //webapi接受多个对象处理方式
      //console.log(pdata);
      let ss_string=this.$store.getters.data().ss_string
      let refresh_table=this.$store.getters.data().refresh_table;
      //
      let toData_username=new Array();
      for(var i=0;i<=this.$refs.jroadeparttree.toData.length-1;i++){
        toData_username.push(this.$refs.jroadeparttree.toData[i].username);
      }
      var turl =
        "/api"+refresh_table.table.url+"Audit_tj?reimids=" +
        ss_string +
        "&pdata=" +
        pdata+
        "&hq_tousername="+toData_username.join(',');
        //console.log(toData_username);
        // return;
      this.http.post(turl, {}, true).then((result) => {
        if (!result.status) {
           this.$store.getters.data().refresh_table.refresh();
           this.$message.error(result.message);
           this.model = false;
           this.$refs.jroadeparttree.toData.splice(0, this.$refs.jroadeparttree.toData.length); //清空数组 汇签人列表操作完成后 清空数据
          return        
        } else {
          this.$Message.info(result.message);
          refresh_table.refresh(); 
          this.model = false;
          this.$refs.jroadeparttree.toData.splice(0, this.$refs.jroadeparttree.toData.length); //清空数组 汇签人列表操作完成后 清空数据
        }
      });
    },
    guanbi(){
      this.model =false;
      this.$refs.jroadeparttree.toData.splice(0, this.$refs.jroadeparttree.toData.length); //清空数组 汇签人列表操作完成后 清空数据
    }
  },
};
</script>



